package com.wzh.yebServe.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.wzh.yebServe.pojo.*;
import com.wzh.yebServe.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.List;

/**
 * @Author wzh
 * @create 2022/11/19 18:34
 * @Description:
 */
@RequestMapping("/employee/basic")
@RestController
@RequiredArgsConstructor
@Api(tags = "EmployeeController  员工管理接口")
public class EmployeeController {

    private final IEmployeeService iEmployeeService;

    private final INationService iNationService;

    private final IPoliticsStatusService iPoliticsStatusService;

    private final IJobLevelService iJobLevelService;

    private final IPositionService iPositionService;

    private final IDepartmentService iDepartmentService;


    @ApiOperation("获取所有员工(分页)")
    @GetMapping("/")
    public RespPageBean getEmployeeByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                          @RequestParam(defaultValue = "10") Integer size,
                                          Employee employee,
                                          LocalDate[] beginDateScope) {
        return iEmployeeService.getEmployeeByPage(currentPage, size, employee, beginDateScope);
    }

    @ApiOperation(value = "获取所有的民族信息")
    @GetMapping("/nation")
    public List<Nation> getAllNations() {
        return iNationService.list();
    }

    @ApiOperation(value = "获取所有政治面貌信息")
    @GetMapping("/politicsStatus")
    public List<PoliticsStatus> getAllPoliticsStatus() {
        return iPoliticsStatusService.list();
    }


    @ApiOperation(value = "获取所有职位")
    @GetMapping("/position")
    public List<Position> getAllPosition() {
        return iPositionService.list();
    }

    @ApiOperation(value = "获取所有职称对象")
    @GetMapping("/jebLevel")
    private List<JobLevel> getAllJobLevel() {
        return iJobLevelService.list();

    }

    @GetMapping("/deps")
    @ApiOperation(value = "获取所有部门")
    public List<Department> getAllDepartments() {
        return iDepartmentService.getAllDepartments();
    }

    @GetMapping("/maxWorkId")
    @ApiOperation(value = "获取最大工号")
    public ResultBean maxWorkId() {
        return iEmployeeService.maxWorkId();
    }

    @ApiOperation(value = "添加员工")
    @PostMapping("/addEmp")
    public ResultBean addEmp(@RequestBody Employee employee) {
        return iEmployeeService.addEmp(employee);
    }

    @ApiOperation(value = "更新员工")
    @PutMapping("/")
    public ResultBean updateEmployee(@RequestBody Employee employee) {
        return iEmployeeService.updateEmployee(employee);

    }

    @ApiOperation(value = "删除一个员工")
    @DeleteMapping("/{id}")
    public ResultBean deleteEmployee(@PathVariable("id") Integer id) {
        return iEmployeeService.deleteEmployee(id);
    }


    /**
     * 使用流导出员工数据
     *
     * @param response
     * @throws IOException
     */
    @ApiOperation(value = "导出一个员工信息")
    @GetMapping(value = "/export", produces = "application/octet-stream")
    public void exportEmp(HttpServletResponse response) throws IOException {
        iEmployeeService.exportEmp(response);
    }

    @PostMapping("/import")
    public ResultBean importEmp(MultipartFile file) {
        return iEmployeeService.importEmp(file);
    }
}
